import Vue from 'vue';
import VueRouter from 'vue-router';
import store from '../store';
import { routes } from './routes';
import { cookie } from 'vux';

Vue.use(VueRouter);

const router = new VueRouter({
    mode: 'history',
    routes: routes
});

router.beforeEach((to, from, next) => {
    /*if (/^\/$/.test(to.path) && /^\/main/.test(from.path)) return next(false);*/

    Vue.$vux.loading.show({ text: '加载中' });
    //!0 请你存放有没有登录的变量
    if( store.getters.user && to.matched.some(function (item) { return item.meta.isLogin;})) {
        next({
            path:'/login',
            query: {redirect:to.fullPath}//把要跳转的地址作为参数传到下一步
        });
    }else {
        next();
    }

});

router.afterEach(() => Vue.$vux.loading.hide());

export default router;
